//
//  YZNewFriendVM.m
//  VET
//
//  Created by lixiaoyi on 2018/7/12.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZFriendVM.h"
#import "YZFriendAPI.h"

@implementation YZFriendVM

/**
 查询好友
 
 @param index 序号
 @param size 大小
 @return 处理结果
 */
- (RACSignal *)getFriends:(NSUInteger)index
                     size:(NSUInteger)size {
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [[YZFriendAPI getFriends:index size:size] subscribeNext:^(id  _Nullable x) {
            [subscriber sendNext:x];
            [subscriber sendCompleted];
            
        } error:^(NSError * _Nullable error) {
            
            [subscriber sendError:error];
            [subscriber sendCompleted];
        } completed:^{
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^{}];
    }];
}


/**
 添加朋友
 
 @param targetId 好友id
 @return 处理结果
 */
- (RACSignal *)addFriend:(NSString *)targetId {
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [[YZFriendAPI addFriend:targetId] subscribeNext:^(id  _Nullable x) {
            [subscriber sendNext:x];
            [subscriber sendCompleted];
            
        } error:^(NSError * _Nullable error) {
            
            [subscriber sendError:error];
            [subscriber sendCompleted];
        } completed:^{
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^{}];
    }];
    
}

/**
 删除好友
 
 @param targetId 好友id
 @return 处理结果
 */
- (RACSignal *)deleFriend:(NSString *)targetId {
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [[YZFriendAPI deleFriend:targetId] subscribeNext:^(id  _Nullable x) {
            [subscriber sendNext:x];
            [subscriber sendCompleted];
            
        } error:^(NSError * _Nullable error) {
            
            [subscriber sendError:error];
            [subscriber sendCompleted];
        } completed:^{
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^{}];
    }];
    
}

/**
 是否好友
 
 @param targetId 好友id
 @return 处理结果
 */
- (RACSignal *)isFriend:(NSString *)targetId {
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [[YZFriendAPI isFriend:targetId] subscribeNext:^(id  _Nullable x) {
            [subscriber sendNext:x];
            [subscriber sendCompleted];
            
        } error:^(NSError * _Nullable error) {
            
            [subscriber sendError:error];
            [subscriber sendCompleted];
        } completed:^{
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^{}];
    }];
}

/**
 查询用户信息
 
 @param useId 用户uid
 @return 用户信息
 */
- (RACSignal *)queryUserInfo:(NSString *)useId {
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [[YZFriendAPI queryUserInfo:useId] subscribeNext:^(id  _Nullable x) {
            [subscriber sendNext:x];
            [subscriber sendCompleted];
            
        } error:^(NSError * _Nullable error) {
            
            [subscriber sendError:error];
            [subscriber sendCompleted];
        } completed:^{
            [subscriber sendCompleted];
        }];
        
        return [RACDisposable disposableWithBlock:^{}];
    }];
}

@end
